import request from './request'

// 登录请求
export function login(username, password) {
  return request({
    url: '/login',
    method: 'post',
    data: {
      username,
      password,
    },
  })
}

// 发布或更新文章
export function updateArticle(articleProps) {
  return request({
    url: '/updateArticle',
    method: 'post',
    data: {
      ...articleProps,
      token: sessionStorage.getItem('token'),
    },
  })
}

// 获取用户信息
export function getadminDataByToken() {
  return request({
    url: '/getadminDataByToken',
    params: {
      token: sessionStorage.getItem('token'),
    },
  })
}

// 获取标签
export function getTagInfo() {
  return request({
    url: '/getTagInfo',
    params: {
      token: sessionStorage.getItem('token'),
    },
  })
}

// 获取所有文章
export function getArticleList() {
  return request({
    url: '/getArticleList',
    params: {
      token: sessionStorage.getItem('token'),
    },
  })
}

// 删除文章
export function delArticle(id) {
  return request({
    url: '/delArticle',
    method: 'post',
    data: {
      id,
      token: sessionStorage.getItem('token'),
    },
  })
}

// 根据文章id获取文章信息
export function getArticleById(id) {
  return request({
    url: '/getArticleById',
    method: 'post',
    data: {
      id,
      token: sessionStorage.getItem('token'),
    },
  })
}

// 根据文章id获取文章信息
export function getDiffTypeArticleInfo() {
  return request({
    url: '/getDiffTypeArticleInfo',
    params: {
      token: sessionStorage.getItem('token'),
    },
  })
}

// 获取近七日数据
export function getNearWeekVisitor() {
  return request({
    url: '/getNearWeekVisitor',
    method: 'post',
    data: {
      token: sessionStorage.getItem('token'),
    },
  })
}

// 获取评论列表
export function getCommentList() {
  return request({
    url: '/getCommentList',
    params: {
      token: sessionStorage.getItem('token'),
    },
  })
}

// 修改文章状态
export function changeArticleStatus(id, status) {
  return request({
    url: '/changeArticleStatus',
    method: 'post',
    data: {
      token: sessionStorage.getItem('token'),
      id,
      status
    },
  })
}
// 审核评论状态
export function changeCommentStatus(id, status) {
  return request({
    url: '/changeCommentStatus',
    method: 'post',
    data: {
      token: sessionStorage.getItem('token'),
      id,
      status
    },
  })
}

// 删除评论 
export function deleteCommentById(id) {
  return request({
    url: '/deleteCommentById',
    method: 'post',
    data: {
      token: sessionStorage.getItem('token'),
      id,
    },
  })
}
// 上传markdown图片 
export function uploadImage(base64) {
  return request({
    url: '/uploadImage',
    method: 'post',
    data: {
      token: sessionStorage.getItem('token'),
      base64
    },
  })
}
